In this demo, you will learn about
styling components using external cascading style sheets or
css files as a style sheet. An external style sheet allows
defining styles in a separate file with an external style sheet. The same styles can be
applied to multiple tags. To get started, create a demo react app
using MPX create react app command that will complete the react
project basic setup. Open the created react project in VS code,
now inside the SRC folder in app.js. Delete the code inside the header tag. Next create a folder named
components in the SRC folder. Inside the components folder,
create a component Named component1.jsx. Also create an external style sheet,
component1.css inside the same folder in component1.jsx,
import the css file created above. Add Import.comonent1.css. Now add some code and component1.jsx. You will create a section tag with
the class name attribute with the value section one. Type section class name equals double
quotes section one and close the tag. Lnside the section tag, create a div tag
with class name equals to the wrapper. For this,
add div class name equals wrapper. Next add an image tag with SRC and
all attributes inside the div tag also assigned the image as the class name,
paste an image URL in the code, alt all equals to Tammy Stevens and
class name equals to the image. Now close the image tag, after that define
a tag specifying the same image in app.js, add the component one tag,
import component1 in app.js first and then add the component one
tag inside the header tag. Run the application using
command npm run start and check that the application
runs fine with no styling. So now in styles.css defines some
styles first add styles to the class name wrapper, such as aligning the text
to center and assigning some padding. Similarly add styling to the image by
specifying the margin with etcetera. Now go to the application again to
check if the styles are applied. Here, the component is loaded
with the applied styles, so this is how you style
a component using external css. Thank you.